package main

import (
	"io/fs"
	"net/http"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gres"

	_ "test-gf-mini/packed"
)

type GFPackFS struct {
	Fallback string
}

func (f *GFPackFS) Open(name string) (fs.File, error) {
	file := gres.Get(name)
	if file == nil {
		fullback := gres.Get(f.Fallback)
		return fullback, nil
	}
	return file, nil
}

func main() {
	s := g.Server()
	s.Group("/web", func(group *ghttp.RouterGroup) {
		group.ALL("/*", ghttp.WrapH(http.FileServer(http.FS(&GFPackFS{"web/index.html"}))))
	})
	s.SetPort(8199)
	s.Run()
}
